/**
 * Created by JetBrains PhpStorm.
 * User: Xnfy520@gmail.com
 * Date: 12-3-11
 * Time: 下午11:10
 */
$(function(){



    $("#access-index form.select").submit(function(){
        var key = $("#access-index input[name=key]").val();
        if(key==''){
            alert('搜索节点不能为空');
            return false;
        }
    });

    $("#access-index tbody tr").hover(function(){
        $(this).css("background-color", "white");
    }, function(){
        $(this).css("background-color", "#EFF3F6");
    });


//    $("#access-select .title .back").click(function(){
//        window.history.go(-1);
//    });


    $("#access-index a.add").click(function(){
        var datas = $("#access-index form.delete input:checked").val();
        if(datas==undefined){
            alert('请选择要授权的节点');
            return false;
        }else{
            if(window.confirm('确认授权这些节点?')){
                $("#access-index form.delete").attr('action', $("#access-index form.delete").attr('action')+"/insert");
                $("#access-index form.delete").submit();
            }
        }
    });


    $("#access-index a.delete").click(function(){
        var datas = $("#access-index form.delete input:checked").val();
        if(datas==undefined){
            alert('请选择要取消授权的节点');
            return false;
        }else{
            if(window.confirm('确认取消授权这些节点?')){
                $("#access-index form.delete").submit();
                $("#access-index form.delete").attr('action', $("#access-index form.delete").attr('action')+"/del");
                $("#access-index form.delete").submit();
            }
        }
    });

    $("#access-index a.into").click(function(){
        if($("#access-index form.delete :checked").length==0){
            alert('请先选择节点');
            return false;
       }else if($("#access-index form.delete :checked").length>1){
           alert('进入节点不能多选');
           return false;
       }else{
           var id = $("#access-index form.delete input:checked").val();
           var rid = $("#access-index form .rid").val();
           if(action_name=='index'){
               window.location=APP+"/Access/modelindex/rid/"+rid+"/pid/"+id;
           }else{
               window.location=APP+"/Access/actionindex/rid/"+rid+"/pid/"+id;
           }
       }
    });

    $("#access-index .title .back").click(function(){
        window.history.go(-1);
    });

    $(".back").click(function(){
        window.history.go(-1);
    });


    $("#access-index a.select").toggle(function(){
        $("#access-index input[type=checkbox]").attr('checked', 'checked');
    },function(){
        $("#access-index input[type=checkbox]").attr('checked',null);
    });


});
